@extends('admin.layout.layout', ['row' => @$page])

@section('contain')


    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
                {{--<div class="item">
                    <a href="/{{ request()->path() }}/download_template" class="btn btn-primary">{{ ts('DOWNLOADTEMPLATE') }}</a>
                </div>
                <div class="item">
                    <a href="/{{ request()->path() }}/bulk_import" class="btn btn-primary">{{ ts('BULKIMPORT') }}</a>
                </div>--}}
            </div>
        </div>

        <div class="filter-wrapper">
            <form action="/{{ request()->path() }}/" class="form-inline filter-form">
                <div class=" input-group mb-3 custom-control-inline">
                    <input type="text" class="form-control s-input" name="value" value="{{ request()->input('value') }}" placeholder="{{ ts('PRECUTSEARCHTEXT2') }}" style="width: 480px;">
                </div>
                <x-flatpickr-date-range label="{{ ts('createdat') }}"></x-flatpickr-date-range>
                <div class="mb-3">
                    <button class="btn btn-primary">{{ ts('SEARCH') }}</button>
                    <a href="/{{ request()->path() }}/" class="btn btn-warning">{{ ts('RESET') }}</a>
                </div>

            </form>
        </div>

        <div>
            <table class="table table-s1" data-toggle="table" data-fixed-columns="true" data-fixed-number="1" data-fixed-right-number="1">
                <thead>
                <tr class="order_column">
                    <th></th>
                    <th>{{ ts('sequence') }}</th>
                    <th>{{ ts('PRECUTID') }}</th>
                    <th>{{ ts('year') }}</th>
                    <th>{{ ts('make') }}</th>
                    <th>{{ ts('model') }}</th>
                    <th>{{ ts('jxsmc') }}</th>
                    <th>{{ ts('rollnumber') }}</th>
                    <th>{{ ts('CREATEDAT') }}</th>
                    <th>{{ ts('OPERATIONS') }}</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $k => $v)
                    <tr class="item-list">
                        <td class="text-center">
                            <input type="checkbox" class="warranty_icheck icheck_input" name="ids[]" value="{{ $v->id }}">
                        </td>
                        <td class="text-center">
                            {{ @$data->firstItem()+$k }}
                        </td>
                        <td>
                            {{ @$v->precut_id }}
                        </td>
                        <td>
                            {{ @$v->year_id }}
                        </td>
                        <td>
                            {{ @$v->make_id }}
                        </td>
                        <td>
                            {{ @$v->model_id }}
                        </td>
                        <td>
                            {{ @$v->jxsmc }}
                        </td>
                        <td>
                            @empty(@$coverages[$v->id])
                            @else
                                @foreach(@$coverages[$v->id] as $c)
                                    <div>{{ @$c->roll_number }}</div>
                                @endforeach
                            @endif
                        </td>
                        <td>
                            {{ fdate2(@$v->created_at) }}
                        </td>
                        <td>
                            @if(session('admin.user_type')!=1)
                                <a class="btn btn-primary btn-sm" href='/{{ request()->path() }}/{{ @$v->id }}/install'>{{ ts('INSTALLER') }}</a>
                                <button type="button" class="btn btn-danger btn-sm" onclick="handleFQTH('{{ @$v->id }}', '{{ @$v->precut_id }}')">{{ ts('fqth') }}</button>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>

            <div class="row my-3">
                {{ $data->appends(request()->input())->links() }}
            </div>
        </div>

    </div>


@endsection

@section('script')
    <script>
        function handleFQTH(id, precut_id) {
            var url = '/admin/precut/return';
            var msg = '确认对 '+precut_id+' 发起退货？';
            mySwalV2({t:msg}).then(function (d) {
                request.post('/admin/precut/return', {
                    id: id
                })
                    .then(function (d) {
                        mySwal2()
                    })
                    .catch(function (d) {
                        sw3(d.msg, '系统错误！');
                    });
            }).catch(function (d) {
                console.log(d)
            })
            return id;
        }
    </script>
@endsection